timer = {
	Timers = {},
}
-- accurate to 100 millionths of a second (100 microseconds or 0.00000001)
function timer.start(delay,reps,callback)
	local tmr = {
		StartTime = time.micro(),
		Delay = delay,
		Overflow = 0,
		Started = nil,
		RepeatTimes = reps,
		Callback = callback,
		TimesRan = 0,
	}
	function tmr:Update()
		local delta = (time.micro() - self.StartTime)
		local overlaps = math.floor(delta/self.Delay)
		local shouldRun = (self.TimesRan < self.RepeatTimes) or (self.RepeatTimes <= 0)
		local Delay = self.Delay - self.Overflow
		
		if shouldRun then
			if delta > Delay then
				self.Overflow = (delta-self.Delay) % Delay
				self.StartTime = time.micro()
				for i=0,overlaps do
					if self.TimesRan < self.RepeatTimes then
						self.TimesRan = self.TimesRan + 1
						if self.Callback then self.Callback(self.TimesRan) end
					end
				end
			end
		else
			table.removeValue(timer.Timers, self)
		end
	end
	table.insert(timer.Timers, tmr)
end

function timer:Update()
	for k,t in pairs(self.Timers) do
		t:Update()
	end
end